#include <bits/stdc++.h>
using namespace std;

// 对于https://www.luogu.com.cn/article/krl6f2to 中2^(S-a_i)，这个式子计算的是第i种的贡献的其他珠子选取的“方案数”，至于其他珠子“各自的贡献是多少不用管”
using ll = long long;
const int N = 2e5 + 10;
const ll MOD = 1e9 + 7;
ll cnt[N], v[N];
ll qpow(ll x, ll p)
{
	ll res = 1;
	while (p)
	{
		if (p & 1)
		{
			res = res * x % MOD;
		}
		x = x * x % MOD;
		p >>= 1;
	}
	return res;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, i;
	ll ans = 0, tot = 0;
	cin >> n;
	for (i = 1; i <= n; ++i)
	{
		cin >> cnt[i];
		tot += cnt[i];
	}
	for (i = 1; i <= n; ++i)
	{
		cin >> v[i];
	}
	for (i = 1; i <= n; ++i)
	{
		ans = (ans + qpow(2, tot - cnt[i]) * (qpow(v[i] + 1, cnt[i]) - 1) % MOD) % MOD;
	}
	cout << ans << flush;
	return 0;
}
